/**
  ******************************************************************************
  * File Name          : lorabsp.h
  * Description        : This file provides code for the configuration
  *                      of the lora bsp instances.
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __lorabsp_H
#define __lorabsp_H

#if(COLLECTOR_USE_TYPE == COLLECTOR_USE_LORA)
#include "tskcfg.h"

#define LORA_HOST_Pin             GPIO_PIN_0
#define LORA_HOST_GPIO_Port       GPIOC
#define LoRa_HostWake()           (GPIO_ISTAT(LORA_HOST_GPIO_Port)&(LORA_HOST_Pin))

#define LORA_RELOAD_Pin           GPIO_PIN_2
#define LORA_RELOAD_GPIO_Port     GPIOC
#define LoRa_Reload(x)            x?(GPIO_BOP(LORA_RELOAD_GPIO_Port) = (uint32_t)LORA_RELOAD_Pin):(GPIO_BC(LORA_RELOAD_GPIO_Port) = (uint32_t)LORA_RELOAD_Pin)

#define LORA_PWR_Pin              GPIO_PIN_5
#define LORA_PWR_GPIO_Port        GPIOA
#define LoRa_PwrEn(x)             x?(GPIO_BOP(LORA_PWR_GPIO_Port) = (uint32_t)LORA_PWR_Pin):(GPIO_BC(LORA_PWR_GPIO_Port) = (uint32_t)LORA_PWR_Pin)

#define LORA_RST_Pin              GPIO_PIN_2
#define LORA_RST_GPIO_Port        GPIOE
#define LoRa_Reset(x)             x?(GPIO_BOP(LORA_RST_GPIO_Port) = (uint32_t)LORA_RST_Pin):(GPIO_BC(LORA_RST_GPIO_Port) = (uint32_t)LORA_RST_Pin)

#define LORA_BUF_MAXLEN           240u
#define LORA_PAYLOAD_MAXLEN       232u

#define LORARECV_QUE_LENGTH       3
#define LORARECV_QUE_ITEMSIZE     sizeof(LoRa_BufType)

typedef enum
{
  LORA_SIMPLE_INS       = 0x00U,
	LORA_QUERY_STAT,
	LORA_CHECK_PARA,
	LORA_SET_PARA,
}WHL101_CmdTypeTyp;

typedef struct 
{
  const char  *cstr;   /* command string */
  const char  *rstr;   /* reply string */
  int8_t      rty;     /* number of retries */
  uint32_t    timout;  /* receive wait timeout */
  uint32_t    rtytim;  /* retry interval time */
	WHL101_CmdTypeTyp cmdtype;
}WHL101_CommandTyp;

typedef struct
{
	char stinfo[16];
	char wmode[8];
	char pmode[8];
	char spd[8];
	char fec[8];
	char pwr[8];
	char sendok[8];
}LoRa_ConfigParaType;

typedef struct
{
	uint8_t buf[LORA_BUF_MAXLEN];
	uint8_t count;
}LoRa_BufType;

/********************    +++ppp   ******************************/
extern const WHL101_CommandTyp lora_cmd_ppp;
/********************    a   ******************************/
extern const WHL101_CommandTyp lora_cmd_a;
/********************    AT   ******************************/
extern const WHL101_CommandTyp lora_cmd_at;
/********************    E   ******************************/
extern const WHL101_CommandTyp lora_cmd_e;
/********************    Z   ******************************/
extern const WHL101_CommandTyp lora_cmd_z;
/********************    ENTM   ******************************/
extern const WHL101_CommandTyp lora_cmd_entm;
/********************    CFGTF   ******************************/
extern const WHL101_CommandTyp lora_cmd_cfgtf;
/********************    RELD   ******************************/
extern const WHL101_CommandTyp lora_cmd_reld;
/********************    WMODE   ******************************/
extern const WHL101_CommandTyp lora_cmd_check_wmode;
extern const WHL101_CommandTyp lora_cmd_set_wmode;
/********************    PMODE   ******************************/
extern const WHL101_CommandTyp lora_cmd_check_pmode;
extern const WHL101_CommandTyp lora_cmd_set_pmode;
/********************    SPD   ******************************/
extern const WHL101_CommandTyp lora_cmd_check_spd;
extern const WHL101_CommandTyp lora_cmd_set_spd;
/********************    ADDR   ******************************/
extern const WHL101_CommandTyp lora_cmd_check_addr;
extern const WHL101_CommandTyp lora_cmd_set_addr;
/********************    CH   ******************************/
extern const WHL101_CommandTyp lora_cmd_check_ch;
extern const WHL101_CommandTyp lora_cmd_set_ch;
/********************    FEC   ******************************/
extern const WHL101_CommandTyp lora_cmd_check_fec;
extern const WHL101_CommandTyp lora_cmd_set_fec;
/********************    PWR   ******************************/
extern const WHL101_CommandTyp lora_cmd_check_pwr;
extern const WHL101_CommandTyp lora_cmd_set_pwr;
/********************    SQT   ******************************/
extern const WHL101_CommandTyp lora_cmd_sqt;
/********************    SENDOK   ******************************/
extern const WHL101_CommandTyp lora_cmd_check_sendok;
extern const WHL101_CommandTyp lora_cmd_set_sendok;

extern LoRa_BufType     LoRa_RecvBack;
extern LoRa_BufType     LoRa_RecvIsr;

extern QueueHandle_t    LoRa_Recv_qhd;

extern uint8_t LoRa_Init(void);
extern uint8_t LoRa_LinkLoopback(uint8_t dstid, const uint8_t *payload, uint8_t pllen);

extern uint8_t LoRa_StartUp(void);
extern uint8_t LoRa_Config(uint16_t netid, uint8_t localid, uint8_t channel);

extern uint8_t LoRa_DIDtoChannel(const char *did, uint16_t *netid, uint8_t *channel);

extern void LoRa_UartSendStr(const char *buf);
extern void LoRa_UartSendBuf(const uint8_t *buf, uint32_t len);

extern void LoRa_BspInit(void);

#endif /*#if(COLLECTOR_USE_TYPE == COLLECTOR_USE_LORA) */

#endif /* __lorabsp_H */

/**
  * @}
  */
/************************ (C) COPYRIGHT *****END OF FILE****/
